<?php
/**
 * This file is part of the Agora distribution. 
 * Detailed copyright and licensing information can be found
 * in the gpl-3.0.txt file which should be included in the distribution.
 * 
 * @version		$Id: 3.0.14 Olympus 2010-09-28 rammstein4o $
 * @copyright  2007 - 2010 jVitals
 * @license   GPLv3 Open Source
 * @link       http://jvitals.com
 * @since      File available since initial release
 */
	defined ('IN_AGORA') or die;

	class FeedModel extends Model
	{
		function __construct() {
			parent::__construct();
			$this->limit = 'LIMIT 0,30';
		}

		function getGlobalFeed() {
			$this->setQuery('SELECT p.*,t.subject, f.id as forum_id, f.forum_name as topic_subject FROM ##__posts as p'.
							' INNER JOIN ##__topics AS t'.
							'  ON p.topic_id = t.id'.
							' INNER JOIN ##__forums AS f'.
							'  ON t.forum_id = f.id'.
							'  WHERE p.approved = 1 '.
							' ORDER BY p.posted DESC '.$this->limit);
			return $this->db->loadAssocList();
		}

		function getForumFeed($forum_id) {
			$this->setQuery('SELECT p.*,t.subject AS topic_subject FROM ##__posts as p'.
							' INNER JOIN ##__topics AS t'.
							'  ON p.topic_id = t.id'.
							' WHERE t.forum_id = '.intval($forum_id) . ' AND t.approved = 1 ' .
							' ORDER BY p.posted DESC '.$this->limit);
			return $this->db->loadAssocList();
		}

		function getTopicFeed($topic_id) {
			$this->setQuery('SELECT p.*,t.subject AS topic_subject FROM ##__posts as p'.
							' INNER JOIN ##__topics AS t'.
							'  ON p.topic_id = t.id'.
							'  WHERE topic_id = '.intval($topic_id) . ' AND p.approved = 1 ' .
							' ORDER BY p.posted DESC '.$this->limit);
			return $this->db->loadAssocList();
		}

		function getCategoryFeed($cat_id) {
			$this->setQuery('SELECT p.*, f.id as forum_id, t.subject AS topic_subject FROM ##__posts as p'.
							' INNER JOIN ##__topics AS t'.
							'  ON p.topic_id = t.id'.
							' INNER JOIN ##__forums AS f'.
							'  ON t.forum_id = f.id'.
							' WHERE f.cat_id = '.intval($cat_id) . ' AND p.approved = 1 ' .
							' ORDER BY p.posted DESC '.$this->limit);
			return $this->db->loadAssocList();
		}
		
		function getTopicAll($topic_id) {
			$this->setQuery('SELECT id FROM ##__posts '.
							'  WHERE topic_id = '.intval($topic_id) . ' AND approved = 1 ' .
							' ORDER BY posted DESC ');
			return $this->db->loadResultArray();
		}

	}	
	
?>
